<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>忘记密码</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link rel="stylesheet" type="text/css" href="../../css/all.css" />
		<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vant@1.6/lib/index.css">
		<script src="html5plus://ready"></script>
		<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.min.js"></script>
		<script src="https://cdn.jsdelivr.net/npm/vant@1.6/lib/vant.min.js"></script>
		<script src="../../js/ajax.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript" src="../../js/fanhui.js" ></script>
	</head>
	<body>
		<div id="app">
			<header>
				<van-nav-bar @click-left="onClickLeft" style="background-color: red;">
					<van-icon slot="left" name="arrow-left" color="white"></van-icon>
					<label slot="title" style="color: white;">忘记密码</label>
				</van-nav-bar>
			</header>
			<section>
				<van-cell-group>
					<van-field placeholder="手机号码" v-model="phone"></van-field>

					<van-field center clearable placeholder="验证码(6位数字短信验证码)" use-button-slot v-model="phoneCode">
						<van-button slot="button" size="small" type="danger" @click="send">获取验证码</van-button>
					</van-field>

					<van-field type="password" placeholder="请输入新密码（最少六位)" v-model="pwd"></van-field>

					<van-field type="password" placeholder="确认密码（请再次输入新密码)" v-model="ispwd"></van-field>

				</van-cell-group>

				<van-button size="large" type="danger" style="margin-top: 20px;" @click="tijiao">提交</van-button>
			</section>

		</div>
		<script type="text/javascript">
			var vm = new Vue({
				el: "#app",
				data: {
					phone: "",
					phoneCode: "",
					pwd: "",
					ispwd: ""
				},
				methods: {
					onClickLeft: function() { //返回登录页面
					var login = plus.webview.create("Login.html",login);
					login.show();
					},
					send: function() { //获取验证码
						var _this = this;
						console.log(_this.phone)
						ajax({
							url: "http://dsapi.ysd3g.com/api/SendForgotPasswordPhoneCode",
							dataType: "jsonp",
							data: {
								phone: _this.phone
							},
							success(res) {
								console.log(JSON.stringify(res))
								if (res.Error) {
									_this.$toast.fail(res.Msg);
								} else {
									_this.$dialog.confirm({
										title: '验证码',
										message: res.Code,
										confirmButtonText: '一键复制'
									}).then(() => {
										//一键复制
									}).catch(() => {
										//取消
									});
								}
							}
						})
					},
					tijiao: function() { //提交
						var _this = this;
						console.log(_this.phoneCode)
						if (_this.pwd != _this.ispwd) {
							_this.$toast.fail("两次密码不一致");
						} else {
							ajax({ //验证手机号和验证码
								url: "http://dsapi.ysd3g.com/api/ValidatePhone",
								dataType: "jsonp",
								data: {
									phone: _this.phone,
									phoneCode: _this.phoneCode
								},
								success(res) {
									console.log(res)
									if (res.Error) {
										_this.$toast.fail(res.Msg);
									} else {
										_this.xiugaimima();
									}
								}
							});
						}

					},
					xiugaimima: function() { //修改密码
						var _this = this;
						ajax({
							url: "http://dsapi.ysd3g.com/api/ResetPassword",
							dataType: "jsonp",
							data: {
								phone: _this.phone,
								password: _this.pwd
							},
							success(res) {
								if (res.Error) {
									_this.$toast.fail(res.Msg);
								} else {
									_this.$toast("修改成功!");
										var login = plus.webview.create("Login.html",login);
										login.show();
										plus.webview.close(plus.webview.currentWebview(), "slide-out-left");
								}
							}
						})
					}
				}
			})
		</script>
	</body>
</html>